package com.shiguiwu.dubbo;

import com.shiguiwu.dubbo.service.impl.DemoServiceImpl;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

/**
 * @description: 主类
 * @author: stone
 * @date: Created by 2023/1/16 11:32
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.dubbo
 */
public class Application {

    public static void main(String[] args) {

        startWithBootstrap();
    }

    public static void startWithBootstrap() {
        //前面的文章都在说这个服务配置对象的创建,中间又说了分层域模型,扩展加载机制
        ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
        //为服务配置下服务接口和服务实现,下面两行用来初始化对象就不详细说了
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        //这一个篇章主要说这里:
        DubboBootstrap bootstrap = DubboBootstrap.getInstance();

        ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
        //初始化应用配置
        bootstrap.application(applicationConfig)
                //初始化注册中心配置
                .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
                //初始化协议配置
                .protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
                //初始化服务配置
                .service(service)
                //启动
                .start()
                .await();
    }






}
